package com.example.carrierapp.ui.adapter;

import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.example.carrierapp.ui.main.goodssource.hill.GoodsSourceHillFragment;
import com.example.carrierapp.ui.main.goodssource.history.CompetitionHistoryFragment;

public class FindGoodsSourceMainAdapter extends FragmentPagerAdapter{
    String[] mTitles;
    Fragment mGoodsSourceHillFragment;
    Fragment mCompetitionHistoryFragment;
    public FindGoodsSourceMainAdapter(FragmentManager fm,String[] titles) {
        super(fm);
        mTitles=titles;
    }

    @Override
    public Fragment getItem(int position) {
        Fragment fragment = null;
        switch (position) {
            case 0:
                if (mGoodsSourceHillFragment == null) {
                    mGoodsSourceHillFragment = GoodsSourceHillFragment.Companion.newInstance();
                }
                fragment = mGoodsSourceHillFragment;
                break;
            case 1:
                if (mCompetitionHistoryFragment == null) {
                    mCompetitionHistoryFragment = CompetitionHistoryFragment.Companion.newInstance();
                }
                fragment = mCompetitionHistoryFragment;
                break;
        }
        return fragment;
    }

    @Override
    public int getCount() {
        return mTitles.length;
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return mTitles[position];
    }
}
